#include<stdio.h>
#include<string.h>
struct Stu {
	char name[20];
	int age;
};
int cmp_struct_age(void* e1,void* e2) {
	return ((struct Stu*)e1)->age - ((struct Stu*)e2)->age;
}
int cmp_struct_name(void* e1, void* e2) {
	return strcmp(((struct Stu*)e1)->name , ((struct Stu*)e2)->name);
}
void Swap(char* buf1,char* buf2,int width) {
	char tmp = 0;
	int i = 0;
	for (i = 0; i < width; i++) {
		tmp = *buf1;
		*buf1 = *buf2;
		*buf2 = tmp;
		buf1++;
		buf2++;
	}
}
void bubble_sort(void* base,size_t sz,size_t width,int (*cmp)(void* e1,void* e2)) {
	size_t i = 0;
	size_t j = 0;
	for (i = 0; i < sz - 1; i++) {
		for (j = 0; j < sz - 1 - i; j++) {
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width) > 0) {
				Swap((char*)base + j * width, (char*)base + (j + 1) * width,width);
			}
		}
	}
}
void test() {
	struct Stu s[3] = {{"zhangsan",20},{"lisi",40},{"wangwu",30}};
	int sz = sizeof(s) / sizeof(s[0]);
	int width = sizeof(s[0]);
	bubble_sort(s, sz, width, cmp_struct_name);
}
int main(){
	test();
	return 0;
}